package gdr.internet;

import java.net.*;  
import java.io.*;  

public class InternetClient implements Runnable{  
	String nome;
	public InternetClient(String nome){ this.nome = nome;
	System.out.println("CLIENT");
	}
	
	public void run(){
		try{  
			Socket s = new Socket("localhost",22222);  
			
			ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());  
			ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
			
			int c = 0;
			try{System.out.println("AAAAA");
			System.out.println(ois.readObject());
			System.out.println("BBBBB");
			oos.writeObject("messaggio");
			System.out.println("CCCCC");
			}catch (Exception e){e.printStackTrace();}/*
			oos.writeObject(nome);
			while (true){
				c++;
				if (c==10) break;
				try{ //do what you want to do before sleeping
						Thread.sleep(3000);//sleep for 1000 ms
					  //do what you want to do after sleeptig
				} catch(InterruptedException ie){System.out.println("CCC");}
				oos.writeObject(new Test(c, "AAAA"));
				//System.out.println(">>>>>>>"+ois.readObject());
			}*/
			oos.close();
			ois.close();
			s.close(); 
		}catch(Exception e){System.out.println(e);}
	} 
}

class Test implements Serializable{
	protected int a;
	protected String b;
	
	public Test(int a, String b){
		setA(a);
		setB(b);
	}
	
	public int getA() {
		return a;
	}
	public void setA(int a) {
		this.a = a;
	}
	public String getB() {
		return b;
	}
	public void setB(String b) {
		this.b = b;
	}

	@Override
	public String toString() {
		return "Test [a=" + a + ", b=" + b + "]";
	}
}